package net.gcode.sdkscheduleparser.core.read;

import java.io.IOException;
import java.io.StringReader;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.Vector;

import net.fortuna.ical4j.data.CalendarBuilder;
import net.fortuna.ical4j.data.ParserException;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.ComponentList;
import net.fortuna.ical4j.model.component.VEvent;
import net.gcode.sdkscheduleparser.core.Vorlesung;
import net.gcode.sdkscheduleparser.intface.ScheduleParser;

public class ICS_Parser implements ScheduleParser {

	@Override
	public Vector<Vorlesung> parse(String TextToParse) {
		StringReader sin = new StringReader(TextToParse);
		Vector<Vorlesung> vorlesungen = new Vector<Vorlesung>();
		CalendarBuilder builder = new CalendarBuilder();
		Calendar calendar= new Calendar();
		try {
			 calendar = builder.build(sin);
			 ComponentList cl=calendar.getComponents();
			Iterator<VEvent> it= cl.iterator();
			 while(it.hasNext()){
				 VEvent event=it.next();
				 java.util.Calendar start=new GregorianCalendar();
				 start.setTime(event.getStartDate().getDate());
				 java.util.Calendar ende=new GregorianCalendar();
				 ende.setTime(event.getEndDate().getDate());
				 Vorlesung vor= new Vorlesung(start,ende,event.getSummary().getValue(),event.getLocation().getValue(),event.getDescription().getValue());
				 vorlesungen.add(vor);
				 //event.get
			 
			 }
			// VEvent event calendar.get
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return vorlesungen;
	}

	@Override
	public int getSemester(String TextToParse) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getStudiengang(String TextToParse) {
		// TODO Auto-generated method stub
		return null;
	}

}
